<template>
  <el-dialog v-model="centerDialogVisible" @close="store.$patch({ rechange: false })" :show-close="false" align-center
    class="rechangeDialog" width="700px">
    <ul>
      <li class="left">
        <span>{{ $t('language.rechange.wallet') }}</span>
        <dl>
          <dd v-for="(item, index) in tab" :class="store.isRecord == index ? 'active' : ''"
            @click="RechangeOrRecord(index)">
            <NuxtImg :src="item.img" alt="" />
            <span>{{ $t(item.lang) }}</span>
          </dd>
        </dl>
      </li>
      <li class="right">

        <div class="compent">
          <WalletchildChangePage v-if="store.isRecord == 0"></WalletchildChangePage>
          <!-- <changePage ></changePage> -->
         <WalletchildRecord v-else/>
        </div>


      </li>
    </ul>
    <!-- <main class="main">
      <header>
        <span @click.stop="$back"></span>
        <dl>
          <dd v-for="(item, index) in tab" :class="activeindex == index ? 'active' : ''" @click="activeindex = index">
            {{ $t(item) }}
          </dd>
        </dl>
        <strong @click="store.$patch({ rechange: false })"><el-icon size="18">
            <CloseBold />
          </el-icon></strong>
      </header>
      <template v-if="activeindex == 0">
        <Skeleton :loading="loading">
          <template #ske>
            <div style="
            width: 100%;
            display: flex;
            justify-content: start;
            align-items: center;
            padding: 0 16px;
          ">
              <el-skeleton-item variant="text" style="width: 60px; height: 36px; margin: 10px 10px 0px 0" />
              <el-skeleton-item variant="text" style="width: 60px; height: 36px; margin: 10px 0 0px 0" />
            </div>
          </template>
<template #main>
            <ul>
              <li v-for="(item, index) in bar" :class="activeBindex == index ? 'activeB' : ''"
                @click="store.$patch({rechangeType:index}) ">
                <img :src="item.img" alt="" />
                <strong>{{ item.name }}</strong>
              </li>
            </ul>
          </template>
</Skeleton>

<component :loading="loading" :is="activeBindex == 0 ? BRL : USDT" />
</template>
<template v-else>
        <dl class="record" v-if="recordinfo.list.length != 0">
          <dd v-for="(item, index) in recordinfo.list" :key="index">
            <p class="time">{{ item.date }}</p>
            <div class="record-item" v-for="child in item.data " :key="child.orderID">
              <div>
                <p>{{ $t('language.rechange.orderID') }}: {{ child.orderID }}</p>
                <i>{{ $t('language.rechange.copy') }}</i>
              </div>
              <span>{{ $t('language.rechange.RechargeAmount') }}: <strong>{{ child.amount / 100 }}R$</strong></span>
              <div class="status">
                <strong>{{ child.orderDate }}</strong>
                <span v-if="child.orderStatus == 0">{{ $t('language.rechange.waitpay') }}</span>
                <span v-else style="color: #0c730c;">{{ $t('language.rechange.paysuccess') }}</span>
              </div>
            </div>
          </dd>
        </dl>
        <div class="nodata" v-if="recordinfo.list.length == 0 && !loadingrecord">
          <img src="@/assets/img/bg4.png" alt="" />
          <p>{{ $t("language.rechange.tips") }}</p>
        </div>
      </template>
</main> -->
  </el-dialog>

</template>
<script setup lang="ts">
// const { proxy } = getCurrentInstance();
import { reactive, ref,shallowRef, nextTick, watch } from "vue";
let loading = shallowRef<boolean>(true);
let activeindex = shallowRef<number>(0);
const store = useStore()
let centerDialogVisible = computed((): boolean => store.$state.rechange)
let recordtitle = shallowRef<string>('language.rechange.deposit')
// 充值与记录切换

let RechangeOrRecord = (index: number): void => {
  index == 0 ? store.$patch({ rechangeType: 2 }) : ""
  store.$patch({ isRecord: index })
  recordtitle.value = tab[index]['title']
}

let activeBindex = computed((): number => store.rechangeType);
let tab = reactive<{ img: string, lang: string, title: string }[]>([{ img: "/img/wallet.png", lang: "language.rechange.title1", title: "language.rechange.deposit" }, { img: "/img/record.png", lang: "language.rechange.title2", title: "language.rechange.record" }]);
let bar = reactive<{ img: string, name: string }[]>([
  {
    img: "/img/mylrft.png",
    name: "BRL",
  },
  {
    img: "/img/t1.png",
    name: "USDT",
  },
]);
//获取充值数据

let userinfo = computed(() => store.$state.userinfo)
//获取充值记录
let record = reactive({
  id: userinfo.value.gameIDs,
  pageIndex: 1,
  pageSize: 30
})
let recordinfo: any = reactive({
  list: [],
  pageIndex: 1,
  pageSize: 11,
  totalCount: 23
})
let loadingrecord = shallowRef<boolean>(false)
watch(() => activeindex.value, (newValue) => {
  if (centerDialogVisible.value != true) return
  if (newValue == 1) {
    loadingrecord.value = true
    ElLoading.service({
      lock: true,
      background: 'rgba(0, 0, 0, 0.7)',
      customClass: 'el-loading'
    })
    useHttpPOST(`/Payment/v1.0/Web/User/Recharge/List`, record)
      .then((res: any) => {
        for (let key in res.data.value.data.data) {
          recordinfo[key] = res.data.value.data[key];
        }
      }).finally(() => {
        ElLoading.service({
          lock: true,
          background: 'rgba(0, 0, 0, 0.7)',
          customClass: 'el-loading'
        }).close()
        loadingrecord.value = false
        GetUserInfo(userinfo).then(({ data }: { data: any }) => {
          store.$patch({ coininfo: data.value.data.accounts })
          store.$patch({ cointype: "BRL" })
          store.$patch({ loginopen: false })
        })
        // let time = setInterval(() => {
        //   ElLoading.service({
        //     lock: true,
        //     background: 'rgba(0, 0, 0, 0.7)',
        //     customClass: 'el-loading'
        //   }).close()
        //   loadingrecord.value = false
        //   clearInterval(time)
        // }, 500)

      });
  }
}, {
  immediate: true
})
let openRechange = (index: number = 0) => {
  store.$patch({ rechange: true })
  store.$patch({ rechangeType: index })
}

//dom更新后执行
onMounted(() => {
  nextTick(() => {

    loading.value = false;
    // let time = setInterval(() => {
    //   loading.value = false;
    //   clearInterval(time);
    // }, 500);
  });
})

//获取充值记录
// proxy.$get(``);
//暴露属性
defineExpose({
  openRechange
})
</script>
<style lang="scss">
.rechangeDialog {
  padding: 0px !important;

  border-radius: 10px;
  background-color: rgb(35, 38, 42) !important;
  overflow-y: auto;


  &::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
  }
}
</style>
<style scoped lang="scss">
.rechangeDialog {
  background-color: rgb(35, 38, 42);
}

ul {
  width: 100%;
  min-height: 76vh;
  height: 76px;
  @include flex(row, space-between, flex-start);

  .left {
    width: 200px;
    height: 100%;
    background-color: rgb(35, 38, 42);
    padding: 0 15px;

    >span {
      display: block;
      height: 48px;
      line-height: 48px;
      font-size: 18px;
      text-align: left;
      color: #fff;
    }

    dl {
      margin-top: 15px;
      @include flex(column, center, flex-start);
      width: 100%;

      dd {

        width: 100%;
        @include flex(row, center, center);
        position: relative;
        cursor: pointer;
        height: 42px;
        line-height: 42px;
        background: #1c1f21;
        text-align: center;
        border-radius: 10px;
        transition: opacity .3s ease;

        &:hover {
          opacity: 0.7;
        }

        span {
          font-size: 14px;
          color: #b5bac8;
        }

        img {
          width: 20px;
          margin-right: 5px;
        }
      }

      dd+dd {
        margin-top: 15px;
      }

      .active {
        span {
          color: #fff;
        }

        background-color: #0a906d;

      }
    }
  }

  .right {
    flex: 1;
    height: 100%;
    background-color: rgb(50, 53, 62);
    @include flex(column, flex-start, center);

    .title {
      width: 100%;
      height: 55px;
      @include flex(row, space-between, center);
      background-color: rgb(35, 38, 42);
      padding: 0 16px;

      span {
        color: #b5bac8;
        font-size: 18px;
      }

      strong {
        height: 28px;
        width: 28px;
        border-radius: 16px;
        @include flex(row, center, center);
        border: 2px solid #fff;
        cursor: pointer;
      }
    }

    .compent {
      flex: 1;
      overflow-y: auto;

      &::-webkit-scrollbar {
        display: none;
      }

      width: 100%;
    }

  }
}

.main {
  width: 100%;

  header {
    width: 100%;
    @include flex(row, space-between, center);
    background-color: rgb(36, 39, 43);
    padding: 20px 20px 6px;
    color: #fff;

    strong {
      display: block;
      height: 30px;
      width: 30px;
      @include flex(row, center, center);
      border: 2px solid #fff;
      border-radius: 16px;
      cursor: pointer;

      img {
        width: 100%;
        height: 100%;
      }
    }

    span {
      width: 34px;
      height: 34px;
      display: block;
    }

    dl {
      flex: 1;
      @include flex(row, center, center);

      dd {
        color: #8e8e8c;
        font-size: 18px;
        position: relative;
        cursor: pointer;
      }

      .active {
        color: #fff;

        &::after {
          content: "";
          position: absolute;
          width: 60%;
          bottom: -4px;
          height: 2px;
          background-color: #fff;
          margin-left: -30%;
          left: 50%;
        }
      }

      dd+dd {
        margin-left: 20px;
      }
    }
  }

  >ul {
    height: 44px;
    width: 100%;
    padding: 0 16px;
    @include flex(row, flex-start, center);
    background-color: rgb(20, 23, 23);

    li {
      height: 44px;
      @include flex(row, flex-start, center);
      border-bottom: 2px solid transparent;
      cursor: pointer;

      img {
        width: 24px;
        margin-right: 5px;
      }

      strong {
        color: #b5bac8;
        font-size: 17px;
      }
    }

    .activeB {
      strong {
        color: #0a906c;
      }

      border-bottom: 2px solid #0a906c;
    }

    li+li {
      margin-left: 20px;
    }
  }

  .record {
    width: 100%;

    dd {
      width: 100%;

      >p {
        height: 40px;
        width: 100%;
        padding: 0 16px;
        line-height: 40px;
        font-size: 14px;
        background-color: #40434c;
        color: #b5bac8;
      }

      .record-item {
        padding: 16px;

        >div {
          @include flex(row, space-between, center);

          p {
            color: #fff;
            font-size: 14px;
          }

          i {
            font-style: normal;
            color: #0a906c;
            font-size: 15px;
          }
        }

        >span {
          font-size: 14px;
          color: #fff;
          display: block;
          margin: 6px 0;
        }

        .status {
          @include flex(row, space-between, center);

          strong {
            color: #666;
            font-weight: normal;
          }

          span {
            font-size: 14px;
            color: #f9e009;
          }
        }
      }

      .record-item+.record-item {
        border-top: 1px solid #40434c;
      }
    }

  }

  .nodata {
    width: 100%;
    height: 400px;

    img {
      width: 200px;
    }

    @include flex(column, center, center);

    p {
      font-size: 17px;
      color: #b5bac8;
      margin-top: 50px;
    }
  }
}
</style>
